package com.dfbz.demo;

import java.util.Stack;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo07_Stack {

    public static void main(String[] args) {
        Stack<String> stack=new Stack<>();
        stack.push("虾饺");
        stack.push("潮汕牛肉丸");

        System.out.println(stack);          // [虾饺, 潮汕牛肉丸]

//        String ele = stack.pop();           // 从栈顶删除一个元素并返回
        String ele = stack.peek();           // 获取栈顶的一个元素,该元素并不会从集合中删除
        System.out.println(ele);            // 潮汕牛肉丸

        System.out.println(stack);          // [虾饺]
    }
    public static void test(String[] args) {

        Stack<String> stack=new Stack<>();
        stack.add("北京");
        stack.add("上海");
        stack.add("广州");
        stack.add("深圳");

        System.out.println(stack);

        stack.set(1,"南京");
        stack.set(2,"佛山");

        System.out.println(stack);

        String str = stack.get(0);
        System.out.println(str);
    }
}
